//
//  CFindViewController.m
//  Btpin
//
//  Created by Vic on 2019/12/16.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CFindViewController.h"
#import "LYSegmentView.h"
#import "GeneralWebViewViewController.h"
#import "CFindPublishNewsFlashViewController.h"

#import "PFindNewsFlashViewController.h"
#import "PFindNewsViewController.h"

@interface CFindViewController ()<LYSegmentViewDelegate>
{
    UIButton *btn;
}
//@property (nonatomic, strong) GeneralWebViewViewController *firstVC;
@property (nonatomic, strong) GeneralWebViewViewController *twoVC;
@property (nonatomic, strong) PFindNewsFlashViewController *firstVC;
//@property (nonatomic, strong) PFindNewsViewController *twoVC;
@property (nonatomic, strong) UIView *currentView;
@end

@implementation CFindViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    [self createSubview];
}
- (void)initUI {
    LYSegmentView *segmentView = [[LYSegmentView alloc] initWithFrame:CGRectMake(0, 0, 200*Scale, 30)];
    segmentView.delegate = self;
    [segmentView setSegmentWithBackground:[UIColor whiteColor] titleArray:@[@"职场快讯", @"新闻资讯"] titleFont:FontBold(Font_18) titleLineSelectColor:THEMECOLOR_OF_TEXT_333333 normal:THEMECOLOR_OF_TEXT_9a9a9a withselectedIndex:0];
    [segmentView setRightTopLabelWithAry:@[@"0", @"0"]];
    self.navigationItem.titleView = segmentView;
}
- (void)createSubview {
//    _firstVC = [[GeneralWebViewViewController alloc] init];
//    _firstVC.showTabBar = YES;
//    _firstVC.showType = GeneralWebViewTypeOfNewsFlash;
//    _firstVC.url = @"https://api.btpin.com/h5/article/lists?channel=job";
    _firstVC = [[PFindNewsFlashViewController alloc] init];
    [self addChildViewController:_firstVC];
    
    _twoVC = [[GeneralWebViewViewController alloc] init];
    _twoVC.showTabBar = YES;
    _twoVC.showType = GeneralWebViewTypeOfNews;
    _twoVC.url = @"https://api.btpin.com/h5/article/lists?channel=news";
//    _twoVC = [[PFindNewsViewController alloc] init];
    [self addChildViewController:_twoVC];
    
    self.currentView = _firstVC.view;
    [self.view addSubview:_firstVC.view];
    
    btn = [UIToolsControl initButtonWithFrame:CGRectMake(WIDTH-60, HEIGHT-HeightOfTabBar-HeightOfStatusBarAndNavigationBar-90, 50, 50) imageName:@"post_newsflash_icon" target:self action:@selector(btnTap) title:nil titleColor:nil];
    [self.view addSubview:btn];
}
#pragma mark -- Action
- (void)customSegmentedValueChanged:(UISegmentedControl *)segment{
    NSLog(@"点击button----%ld", segment.selectedSegmentIndex);
    [self.currentView removeFromSuperview];
    switch (segment.selectedSegmentIndex) {
        case 0: {
            [self.view addSubview:_firstVC.view];
            self.currentView = _firstVC.view;
            btn.hidden = NO;
            [self.view bringSubviewToFront:btn];
        } break;
        case 1: {
            [self.view addSubview:_twoVC.view];
            self.currentView = _twoVC.view;
            btn.hidden = YES;
        } break;
        default:
            break;
    }
}
- (void)btnTap {
    CFindPublishNewsFlashViewController *vc = [[CFindPublishNewsFlashViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
